#coding=utf-8
from django.shortcuts import render,redirect
from django.shortcuts import render_to_response
import sys
from django.http import HttpResponseRedirect
# from django.contrib.auth import authenticate,login,logout
# from django.contrib.auth.decorators import login_required

reload(sys)
sys.setdefaultencoding("utf8")

#首页
def GDG_Test(request):
    return render_to_response('index.html')

#登录页面
def login_index(request):
    return render(request, 'login_index.html')

def login(request):
    new_mobile = request.POST.get('mobile')
    new_password = request.POST.get('password')
    from TestWeb_login_register import login
    login_msg = login.login(new_mobile, new_password)
    if login_msg == '登录成功':
        return HttpResponseRedirect('/index/')
    if login_msg == '密码错误':
        return render(request, 'test_result.html', {'testmsg': login_msg})
    if login_msg == '该账号未注册':
        return HttpResponseRedirect('/register_index/')  #跳转到注册页面

#注册页面
def register_index(request):
    return render(request, 'register_index.html')

def register(request):
    new_mobile = request.POST.get('mobile')
    new_password = request.POST.get('password')
    new_name = request.POST.get('name')
    from TestWeb_login_register import register
    register_msg = register.register(new_mobile, new_password, new_name)
    if register_msg == '注册成功':
        return HttpResponseRedirect('/index/')
    if register_msg == '该手机号码已注册':
        return HttpResponseRedirect('/register_index/')  # 跳转到注册页面

#删除用户
def delete_user(request):
    new_phone = request.GET.get('phone')
    new_status = request.GET.get('status')
    import delete_user
    return render(request, 'test_result.html', {'testmsg': delete_user.delete(new_phone,new_status)})

#用户申请购买并返回验证码
def purchaseApply(request):
    new_mobile = request.GET.get('mobile')
    new_purchaserName = request.GET.get('purchaserName')
    new_auditStatus = request.GET.get('auditStatus')
    new_productId = request.GET.get('productId')
    import purchaseApply
    return render(request, 'test_result.html', {'testmsg': purchaseApply.submit(new_mobile, new_purchaserName,new_auditStatus,new_productId)[0]})

#计划任务页面
def task(request):
    return render(request, 'task.html')

#随机生成银行卡号
def banid(request):
    import bankid
    return render(request, 'test_result.html', {'testmsg':bankid.bankid()})

#随机生成身份证号码
def IDcard(request):
    import ID_card
    return render(request, 'test_result.html', {'testmsg':ID_card.idcard_generator()})

#随机上传朵云社区文章
def News(request):
    new_mobile = request.GET.get('mobile')
    new_articleCategoryId = request.GET.get('articleCategoryId')
    new_showKeywords = request.GET.get('showKeywords')
    import downloadNews
    return render(request, 'test_result.html', {'testmsg':downloadNews.News(new_mobile,new_articleCategoryId,new_showKeywords)[0]})

#发送系统通知消息
def put(request):
    new_category = request.GET.get('category')
    new_commuity_no = request.GET.get('commuity_no')
    new_content = request.GET.get('content')
    new_num = request.GET.get('num')
    import put_information
    return render(request, 'test_result.html', {'testmsg':put_information.put(new_category,new_commuity_no,new_content,new_num)})

#对文章进行评论
def comment(request):
    new_phone = request.GET.get('phone')
    new_content = request.GET.get('content')
    new_num = request.GET.get('num')
    new_articleId = request.GET.get('articleId')
    import reply
    return render(request, 'test_result.html', {'testmsg':reply.comment(new_phone,new_content,new_num,new_articleId)[0]})

#对评论进行回复
def reply(request):
    new_phone = request.GET.get('phone')
    new_content = request.GET.get('content')
    new_num = request.GET.get('num')
    new_commentId = request.GET.get('commentId')
    import reply
    return render(request, 'test_result.html', {'testmsg':reply.reply(new_phone,new_content,new_num,new_commentId)})

#官网-发布文章
def put_article(request):
    new_category = request.GET.get('category')
    new_orders = request.GET.get('orders')
    import ow_login
    return render(request, 'test_result.html', {'testmsg':ow_login.put_article('chenqiang',new_category,new_orders)})

#官网-发布职位信息
def put_position(request):
    new_name = request.GET.get('name')
    new_department = request.GET.get('department')
    new_orders = request.GET.get('orders')
    new_status = request.GET.get('status')
    import ow_login
    return render(request, 'test_result.html', {'testmsg':ow_login.put_position('chenqiang',new_name,new_department,new_orders,new_status)})

#API-TEST-NO1-checkmobile
def checkmobile(request):
    new_status = request.GET.get('status')
    from TestWeb.api_test import api
    return render(request, 'test_result.html', {'testmsg': api.check(new_status)})

#API-TEST-NO2-find
def find(request):
    new_status = request.GET.get('status')
    from TestWeb.api_test import api
    return render(request, 'test_result.html', {'testmsg': api.find(new_status)})


#注册合伙人的全部流程自动化
def partner(request):
    new_mobile = request.GET.get('mobile')
    new_password = request.GET.get('password')
    new_productId = request.GET.get('productId')
    from TestWeb.AutoApitest import duoyun_autoApitest
    return render(request, 'test_result.html', {'testmsg':duoyun_autoApitest.partner(new_mobile,new_password,new_productId)})

#注册成员的全部流程自动化
def member(request):
    new_mobile = request.GET.get('mobile')
    new_password = request.GET.get('password')
    from TestWeb.AutoApitest import duoyun_autoApitest
    return render(request, 'test_result.html', {'testmsg':duoyun_autoApitest.member(new_mobile,new_password)})